﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TuyennvLibrary.ServerApi.Sms
{
    public class MsgContent:IList<MtInfo>
    {
        private List<MtInfo> list_mt { get; set; }
        public MsgContent()
        {
            list_mt = new List<MtInfo>();
        }
        public MsgContent(MtInfo mt1, MtInfo mt2, MtInfo mt3)
        {
            Add(mt1);
            Add(mt2);
            Add(mt3);
        }
        public int IndexOf(MtInfo item)
        {
            return list_mt.IndexOf(item);
        }

        public void Insert(int index, MtInfo item)
        {
            list_mt.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            list_mt.RemoveAt(index);
        }

        public MtInfo this[int index]
        {
            get
            {
                return list_mt[index];
            }
            set
            {
                list_mt[index] = value;
            }
        }

        public void Add(MtInfo item)
        {
            if(item!=null&&!string.IsNullOrEmpty(item.content))
            list_mt.Add(item);
        }
        public List<MtInfo> getListMT()
        {
            return this.list_mt;
        }
        public void Clear()
        {
            this.list_mt.Clear();
        }

        public bool Contains(MtInfo item)
        {
            return list_mt.Contains(item);
        }

        public void CopyTo(MtInfo[] array, int arrayIndex)
        {
            this.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return list_mt.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(MtInfo item)
        {
            return list_mt.Remove(item);
        }

        public IEnumerator<MtInfo> GetEnumerator()
        {
            return list_mt.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return list_mt.GetEnumerator();
        }
        public override string ToString()
        {
            string result = "";
            for (int i = 0; i < Count; i++)
            {
                MtInfo mt = this[i];
                result += string.Format("{0}|{1}|{2}|{3}|{4}{5}", mt.content, mt.userid, (i == 0) ? "1" : "0", mt.content_type,"0",(i<Count-1)?"#":"");
            }
            return result;
        }
    }
}